<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="UTF-8">
  <title>JavaScript 数组 </title>
</head>
<body>
<h2>遍历数组元素 Array.foreach()</h2>


<p id="demo"></p>
<p>Array.forEach() 为每个数组元素调用函数。</p>

<script>
  var fruits, text;
  fruits = ["Banana", "Orange", "Apple", "Mango"];

  text = "<ul>";
  fruits.forEach(myFunction);
  text += "</ul>";
  document.getElementById("demo").innerHTML = text;

  function myFunction(value) {
    text += "<li>" + value + "</li>";
  }
</script>
</body>
</html>